package solver.moves;

import java.util.Random;

import model.IncrementalCostCalculator;
import model.IncrementalValidator;
import model.SolverEnvironment;
import model.Problem;
import model.Solution;

import command.Invoker;

public class SingleRandomProcessToAllMachinesSequential extends AbstractMove{

	public SingleRandomProcessToAllMachinesSequential(SolverEnvironment env) {
		super(env);
	}

	@Override
	public boolean performMove() {
		int p_index = getSingleCandiadateProcess();
		int orig_m_index = env.getPotentialSolution().getMachineIdForProcessId(p_index);
		int start = getRandom().nextInt(getProblem().M);
		int end = start+getProblem().M;
		int m = testSequentiallyNoSchedule(p_index, orig_m_index, start, end);
		if (m!=-1){
			env.getCostCalculator().getProcessMoveToMachineCost(env.getPotentialSolution(),
					p_index, orig_m_index, m);
			makeMove(p_index, orig_m_index, m);
			return true;
		}
		else
			return false;
		
	}
	
	public boolean performMove(int p_index) {
		int start = getRandom().nextInt(getProblem().M);
		int end = start+getProblem().M;
		return testSequentially(p_index, start, end);
	}

}
